<?php

require_once 'init.php';
require_once 'cf/shop.inc';

$page = Page::get('catalog');
$smarty->assign('page',$page);

$product = new Product($par->get('id'));
$smarty->assign('product',$product);

$groups = new ProductGroups($product->id(),true);

$allImages = $images = $product->images();
$smarty->assign('images',$images);
$smarty->assign('imageTexts',$product->imageTexts());
$smarty->assign('attributes',$product->attributes(false,true)->toArray());

$options = $product->options();
$smarty->assign('options',$options);

$optionAttributes = array();
$optionImages = array();
foreach ($options as $option) {	
	$optionAttributes[] = new ProductOptionUniqueAttributes($option->id());
	$img = query2var("SELECT image1 FROM cf_product_options WHERE id=".$option->id());
	$optionImages[] = $img;
	if ($img) {
		$allImages[] = $img;
	}
}
$smarty->assign('allImages',$allImages);
$smarty->assign('optionAttributes',$optionAttributes);
$smarty->assign('optionImages',$optionImages);

$discount = false;
$mainGroupID = false;
foreach ($groups as $gr) {
	if (strpos($gr->code(),'discount') === 0){
		$discount = $gr->code();
	} else if(!$mainGroup && $gr->enabled()) {
		$mainGroupID = $gr->id();		
	}
}
$smarty->assign('discount',$discount);



show(
	'product', 
	$page->name(), 
	Groups::getPath($mainGroupID), 
	$product->tagTitle() ? $product->tagTitle() : ($product->name().' '.$product->model()), 
	$product->tagMetaKeywords(), 
	$product->tagMetaDescr()
);

?>